package homeword.cake;

public class Repository {
    /**
     * 公共类
     */
    private int variate = 0;

    public synchronized void cook() throws InterruptedException {
        String name = Thread.currentThread().getName();

        while (variate < 3) {
            this.variate++;
            System.out.println(name + "厨师，制作了" + this.variate + "个蛋糕");
        }
    }

    public synchronized void consumption() throws InterruptedException {
        String name = Thread.currentThread().getName();

        if (variate >= 3) {
            this.variate--;
            System.out.println(name + "拿走吃掉了1个还剩" + this.variate + "个");
        }
    }
}
